package com.czxy.blogs.manage.service.impl;

import com.czxy.blogs.dao.PartMapper;
import com.czxy.blogs.domain.Part1;
import com.czxy.blogs.manage.service.PartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class PartServiceImpl implements PartService {

    @Autowired
    private PartMapper partMapper;

    @Override
    public List<Part1> findAllPart() {
            return partMapper.selectAll();
    }

    @Override
    public void updatePart(Part1 part) {
        Example example = new Example(Part1.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("pid",part.getPid());
        partMapper.updateByExampleSelective(part,example);
    }

    public Part1 view(String pid){
        Part1 part = partMapper.selectByPrimaryKey(pid);
        return part;
    }

    @Override
    public void deletePart(String pid) {
        partMapper.deleteByPrimaryKey(pid);
    }

    @Override
    public void addPart(Part1 part) {
        partMapper.insertSelective(part);
    }
}
